package com.ziyun.pop.modules.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ziyun.pop.modules.order.dao.OrderItemDao;
import com.ziyun.pop.modules.order.entity.OrderItemEntity;
import com.ziyun.pop.modules.order.service.OrderItemService;
import com.ziyun.pop.modules.order.vo.FactoryOrderItemVo;
import com.ziyun.pop.modules.production.service.ErpOrderItemService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("orderItemService")
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Autowired
    private OrderItemDao orderItemDao;
    @Autowired
    private ErpOrderItemService erpOrderItemService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<OrderItemEntity> page = (Page<OrderItemEntity>) this.page(
                new Query<OrderItemEntity>(params).getPage(),
                new QueryWrapper<OrderItemEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<OrderItemEntity> selectByOrderId(Long orderId) {
        List<OrderItemEntity> result = orderItemDao.selectByOrderId(orderId);
        return result;
    }

    @Override
    public List<FactoryOrderItemVo> selectFactoryOrderItemByOrderId(Long orderId) {
        return orderItemDao.selectFactoryOrderItemByOrderId(orderId);
    }

    @Override
    public boolean updateByMap(Map<String, Object> updateMap, Integer itemId) {
        int count = this.baseMapper.updateByMap(updateMap, itemId);
        if (count == 0){
            return false;
        }
        return true;
    }

}
